package com.wqiuqiu.gulimall.cart.vo;


import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车
 */
public class Cart {

    private List<CartItem> items;

    private int totalCount;

    private int totalType;

    private BigDecimal totalPrice;

    public List<CartItem> getItems() {
        return items;
    }

    public int getTotalCount() {
        int count = 0;
        List<CartItem> items = getItems();
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public int getTotalType() {
        int count = 0;
        List<CartItem> items = getItems();
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getTotalPrice() {

        BigDecimal price = new BigDecimal("0");
        List<CartItem> items = getItems();
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                if (item.getChecked()){
                    price = price.add(item.getTotalPrice());
                }
            }
        }
        return price;
    }
}

